#
# City Utils
# CityUtils By TheLopez
#

from CvPythonExtensions import *
import CvUtil

import sys
import math
import PyHelpers

gc = CyGlobalContext()	

PyPlayer = PyHelpers.PyPlayer
PyGame = PyHelpers.PyGame()

			
# Returns the lists of cities trading with the city passed in that don't 
# belong to the owner of the city passed in.
def getTradeCityList(objCity):
	
	iCounter = 0
	tradeCityList = []

	# Return an empty list immediately if the city passed in is invalid				
	if(objCity == None):
		return []
			
	# Return an empty list immediately if the city passed in is invalid
	if(objCity.isNone()):
		return []
	
	# Get the owner of the city
	iCityOwnerId = objCity.getOwner()
		
	# Go through an endless loop, we'll hopefully break out of it sooner 
	# or later
	while(true):
		objTradeCity = objCity.getTradeCity(iCounter)
		
		# Continue if the owner of the current city is the same as the 
		# owner of the city passed in
		if(iCityOwnerId == objTradeCity.getOwner()):
			iCounter+=1
			continue
			
		# Append the current city to the city list if it is valid
		if (objTradeCity and objTradeCity.getOwner() >= 0):
			tradeCityList.append(objTradeCity)
				
		else:
			break
			
		iCounter+=1
							
	return tradeCityList


			
# Returns the lists of cities trading with the city passed in
def getCompleteTradeCityList(objCity):
	
	iCounter = 0
	tradeCityList = []

	# Return an empty list immediately if the city passed in is invalid				
	if(objCity == None):
		return []
			
	# Return an empty list immediately if the city passed in is invalid
	if(objCity.isNone()):
		return []
	
	# Get the owner of the city
	iCityOwnerId = objCity.getOwner()
		
	# Go through an endless loop, we'll hopefully break out of it sooner 
	# or later
	while(true):
		objTradeCity = objCity.getTradeCity(iCounter)
					
		# Append the current city to the city list if it is valid
		if (objTradeCity and objTradeCity.getOwner() >= 0):
			tradeCityList.append(objTradeCity)
				
		else:
			break
			
		iCounter+=1
							
	return tradeCityList

